package gamebackend;
//TODO this class doesn't seem to do anything special.  Maybe have it so when it swoops back go at half speed or something.
public class SwoopFlier extends AbstractFlier {
	
	private final double my_minX;
	private final double my_maxX;
	/**
	 * Whether the ship is heading directly towards the target.
	 */
	boolean my_pastBend;

	/**
	 * The proportion of the original distance between
	 * the ship and the target by which the ship will
	 * fly away from the target before heading to the target.
	 */
	private final double my_ratio = .8;
	
	public SwoopFlier(Flier the_flier, double the_minX, double the_maxX) {
		super(the_flier);
		my_minX = the_minX;
		my_maxX = the_maxX;
	}

	@Override
	public void step(double the_yChange) {
		super.step(the_yChange);
		if (!my_pastBend && getChild().isAtTarget()) {
			my_pastBend = true;
			getChild().setTarget(getTarget());
		}

	}

	@Override
	public void setTarget(double the_target) {
		super.setTarget(the_target);
		my_pastBend = false;
		final double x = getChild().getPosition();

		getChild().setTarget(Math.max(my_minX, Math.min(my_maxX, x - (the_target - x) * my_ratio)));

	}


	@Override
	public boolean isAtTarget() {
		return my_pastBend && getChild().isAtTarget() ;	
	}

	
	

}
